import json
from math import ceil
from .base_spider import BaseSpider


class QunaerSpider(BaseSpider):
    name = "qunaer"

    def get_datas(self, response):
        content = json.loads(response.text)
        return content['data']['commentData']['comments']

    def get_creator(self, data):
        return data['author']

    def get_create_date(self, data):
        return data['date']

    def get_content(self, data):
        return data['content']

    def get_star(self, data):
        return data['score']

    def get_page_size(self, response):
        return json.loads(response.text)['data']['totalPageNum']


# class QunaerPiaoSpider(QunaerSpider):
#     name = "qunaer_piao"
#
#     def get_datas(self, response):
#         content = json.loads(response.text)
#         return content['data']['commentList']
#
#     def get_page_size(self, response):
#         return int(ceil(json.loads(response.text)['data']['total'] / 10))
